<template>
  <div>
    <!-- 搜索 -->
    <!-- 旧件仓库维护 -车厂-->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable ref="table" :columns="columns" :params="fetchParams" :fetchapi="fetchapi" :datakey="'records'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange">
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" icon="el-icon-check" :click="qiyong.bind()" :disabled="disableds">启用</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-close" :click="tingyong.bind()" :disabled="disableds">禁用</multiuse-button>
        <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="add()">新增</multiuse-button>
        <multiuse-button type="primary" :click="exportFileBtn.bind()">导出</multiuse-button>
        <multiuse-button size="small" type="primary" :loading="exportLoading" :click="downloadTemplate.bind()">下载模板</multiuse-button>
        <multiuse-button size="small" icon="el-icon-upload" @click="showImportFun()">导入</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visibleAdd" :title="'旧件仓库新增'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <AddForm @close="closeAdd" @save="saveAdd"></AddForm>
    </BaseDialog>
    <BaseDialog :visible.sync="visibleEdit" :title="'旧件仓库编辑'" destroyOnClose width="850px" :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <EditForm @close="closeEdit" @save="saveEdit" :rowData="rowData" ></EditForm>
    </BaseDialog>
    <BaseDialog :visible.sync="showImport" icon="el-icon-upload" :closable="false" title="导入" width="800px" destroyOnClose :containerStyle="{ height: 'calc(100% - 120px)', overflow: 'auto', paddingBottom: '60px' }">
      <importExcel @close="showImport = false" @importclose="editsave()" url="/api/cms_claimfac/rPReturnWh/importExcel"/>
    </BaseDialog>
  </div>
</template>
<script>
import Vehicle from '@/pages/claimDemage/tools/vehicle.vue';
import AddForm from './AddForm.vue';
import EditForm from './EditForm.vue';
import { exportExcelFile } from '@/utils/index';
// import importOrderParameterModel from './importOrderParameterModel.vue';
import importExcel from '@/pages/claimDemage/tools/importExcel.vue';
import { getListByPage, newSave, getListForExport, downloadModel ,piliangqiyong, piliangtingyong, excelExport, getDealerList,editSave,exporturl } from '@/api/claim/factory/OldPartWarehouseMaintain';

export default {
  // mixins: [dictionary],
  components: {
    Vehicle,
    AddForm,
    EditForm,
    importExcel
  },
  data() {
    return {
      disableds: true,
      dataList: [],
      visible: false,
      exportLoading: false,
      visibleDrawer: false,
      collapse: false,
      showImport: false,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchapi: getListByPage,
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      dialogTitle: '配件选择',
      visibleAdd: false,
      rowData: {},
      visibleEdit: false
    };
  },
  created() {

  },
  methods: {
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      this.disableds = this.selectedRows.length <= 0;
      console.log(this.selectedRows);
    },
    chooseOrderNo() {
      this.visible = true;
    },
    add() {
      this.visibleAdd = true;
    },
    edit() {
      this.visibleEdit = true;
    },
    //批量启用
    async qiyong() {
      if (this.selectedRows.length > 0) {
        let str = '';
        this.selectedRows.map(x => {
          str += x.whId + ',';
        });
        console.log(str);
        const res = await piliangqiyong({ids: str, status: '1'});
        if (res.resultCode == 200) {
          this.fetchParams = {...this.fetchParams};
        }
      } else {
        return this.$notify.warning({title: '提示信息', message: '请勾选后再进行启用！'});
      }
    },
    //批量停用
    async tingyong() {
      if (this.selectedRows.length > 0) {
        let str = '';
        this.selectedRows.map(x => {
          str += x.whId + ',';
        });
        console.log(str);
        const res = await piliangtingyong({ids: str, status: '0'});
        this.fetchParams = {...this.fetchParams};
      } else {
        return this.$notify.warning({title: '提示信息', message: '请勾选后再进行停用！'});
      }
    },
    closeAdd() {
      this.visibleAdd = false;
    },
    saveAdd() {
      this.visibleAdd = false;
      this.fetchParams = {...this.fetchParams};
    },
    closeEdit() {
      this.visibleEdit = false;
    },
    emitFun(val) {
      this.rowData = val;
      this.visibleEdit = true;
    },
    saveEdit() {
      this.visibleEdit = false;
      this.fetchParams = {...this.fetchParams};
    },
    // Excel更新导入
    showImportFun() {
      this.showImport = true;
    },
    //下载模板
    downloadTemplate() {
      this.$confirm('此操作将下载excel模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.exportLoading = true;
        downloadModel().then(res => {
          console.log('666');
          console.log(res);
          exportExcelFile(res.data, '旧件仓库维护导入模板');
          this.exportLoading = false;
        });
      });
    },
    // 导出
   async exportFileBtn() {
      let json = Object.assign({}, { CODE: 'CODE_00000117' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
    },
    editsave() {
      this.showImport = false;
      this.fetchParams = {...this.fetchParams};
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
      console.log(val);
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {type: 'INPUT', label: '仓库名称', fieldName: 'whName', placeholder: '请输入仓库名称...', initialValue: ''},
        {type: 'INPUT', label: '仓库代码', fieldName: 'whCode', placeholder: '请输入仓库代码...', initialValue: ''},
        {type: 'INPUT', label: '仓库地址', fieldName: 'whAddress', placeholder: '请输入仓库地址...', initialValue: ''},
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 80,
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button size="mini" type="text" onClick={() => this.emitFun(props.row)}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        {title: '状态', dataIndex: 'statusStr', sorter: true},
        {title: '仓库名称', dataIndex: 'whName', sorter: true},
        {title: '仓库代码', dataIndex: 'whCode', sorter: true},
        {title: '仓库地址', dataIndex: 'whAddress', sorter: true},
        {title: '联系人', dataIndex: 'cPerson', sorter: true},
        {title: '联系电话', dataIndex: 'cTel', sorter: true},
        {title: '邮箱', dataIndex: 'eMail', sorter: true},
        {title: '创建人', dataIndex: 'createdBy', sorter: true},
        {title: '创建时间', dataIndex: 'createdAt', sorter: true, width: 140},
        {title: '修改人', dataIndex: 'updatedBy', sorter: true},
        {title: '修改时间', dataIndex: 'updatedAt', sorter: true ,width: 140},
      ];
    }

  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
